/* Copyright 203-2115 AtomWare Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * The flowing information must be keep 
 * PropertyConfiguration.java
 * wholebasic
 * 2013年11月11日上午10:06:22
 * @author 屈甲康
 * QQ285799123
 * mailto:qujiakang@gmail.com
 */

package org.jackysoft.config;

import java.io.File;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.google.common.collect.Lists;

@Configuration("propConfig")
public class ContextConfig extends AbstractSpringConfig{
	public @Value("${pdfServer}")
	String pdfServer;
	public @Value("${rootUrl}")
	String rootUrl;
	public @Value("${pdfServerPort}")
	Integer pdfServerPort = 10086;
	public @Value("${diskBase}")
	String DRIVERNAME;
	public @Value("${imageDir}")
	String imageDir;
	public @Value("${ftphost}")
	String FTPHOST;
	public @Value("${ftpport}")
	int FTPPORT;
	
	public @Value("${mail.host}")
	String mailHost;

	public @Value("${localhost}")
	String LOCALHOST;
	
	@Value("${websockethost}")
	public String websocketHost;
	@Value("${websocketport}")
    public int websocketPort;
	
	@Value("${ftpport}")
	public int ftpport;

	@Value("${updatePort}")
	public int updatePort;
	
	
	@Value("${ftpOn}")
	public boolean ftpOn;
	
	@Value("${websocketOn}")
	public boolean websocketOn;

	@Value("${updateOn}")
	public boolean updateOn;
	
	
	public String pdfPath;
	
	
	@Value("${cas.loginurl}")
	public String casLoginUrl;
	
	@Value("${cas.logouturl}")
	public String casLogoutUrl;
	
	@Value("${cas.server}")
	public String casServer;
	
	@Value("${host.name}")
	public String casHostName;
	
	
	@Value("${newsInfoRoot}")
	public String newsInfoRoot;
	
	@Value("${newsinfoIndexPath}")
	public String newsinfoIndexPath;
	
	
	@Value("${rulesFilePath}")
	public String rulesFilePath;
	
	@Value("${rulesIndexPath}")
	public String rulesIndexPath;
	
	@Value("${attsBase}")
	public String attachmentBase;
	
	@Value("${htmlBase}")
	public String HTMLBase;
	
	@Value("${officeBase}")
	public String OFFICEBase;
	
	@Value("${officeDocBase}")
	public String OFFICEDocBase;
	
	
	
	
	
	public final String FMPATH = "fmtemps";
	private File fileBase;

	@PostConstruct
	public void init() {
		
		fileBase = new File(DRIVERNAME + ":" + File.separator, "files");
		if (!fileBase.exists() && !fileBase.mkdir())
			throw new java.lang.IllegalArgumentException("不能创建目录" + DRIVERNAME);

	}

	public void checkUserDir(String name) {
		File dir = new File(fileBase, name);
		if (!dir.exists() && !dir.mkdir())
			throw new java.lang.IllegalArgumentException("不能创建用户目录:"
					+ dir.getAbsolutePath());

	}

	public String getUserFilebase(String name) {
		return fileBase.getAbsolutePath() + File.separatorChar + name
				+ File.separator;
	}

	

	@Inject
	Environment env;
	
	/**
	 * @return an array present of static path
	 * 
	 * */
	public String[] publicSource(){
	   List<String> publicSources = Lists.newArrayList(
			   "/resources/**", 
			   "/images/**", 
			   "/css/**",
			   "/attachment/**",
			   "/scripts/**",
			   "/logs/**",
			   "/index.jsp",
			   "/admin/treenode/tree-node!ztree*"
			   );
	   
	  
	   logger.info("public resource is : "+publicSources.toString());
	   return publicSources.toArray(new String[0]);
	}
	
    public String	typeAliasesPackage(){
		 return "org.jackysoft.entity,org.jackysoft.workflow";
	}
    
    public String typeHandlerPackage(){
    	return "org.jackysoft.mybatis.type";
    }
	

}
